package com.myc.train.member.controller;

import com.myc.train.common.context.LoginMemberContext;
import com.myc.train.common.resp.CommonResp;
import com.myc.train.common.resp.PageResp;
import com.myc.train.member.req.PassengerQueryReq;
import com.myc.train.member.req.PassengerSaveReq;
import com.myc.train.member.resp.PassengerQueryResp;
import com.myc.train.member.service.PassengerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/passenger")
public class PassengerController {


    @Autowired
    private PassengerService passengerService;

    @RequestMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody PassengerSaveReq req){
        passengerService.save(req);
        return new CommonResp<>();
    }

    @RequestMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq req){
        req.setMemberId(LoginMemberContext.getId());
        PageResp<PassengerQueryResp> list = passengerService.queryList(req);
        return new CommonResp<>(list);
    }


    /**
     *
     * 删除接口，若是根据多个条件删除用下面的-------@PathVariable的含义是路径对应，要把{}中的名字和传参的名字对应
     *     @DeleteMapping("/delete/{id}/{memberID}")
     *     public CommonResp<Object> delete1(@PathVariable Long id,@PathVariable Long memberID)
     * */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        passengerService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/query-mine")
    public CommonResp<List<PassengerQueryResp>> queryMine(){
        List<PassengerQueryResp> passengerQueryResps = passengerService.queryMine();
        return new CommonResp<>(passengerQueryResps);
    }
}
